#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
// #include "camerathread.h"
#include <QMediaDevices>
#include <QHostInfo>
#include <QMessageBox>
#include <QCameraDevice>
#include <QTcpServer>
#include <QTcpSocket>
#include <QNetworkInterface>
#include <QHostAddress>
#include <QFileDialog>
#include <QBluetoothDeviceDiscoveryAgent>
#include <QBluetoothDeviceInfo>
#include <QStringListModel>

#include "observablebool.h"
#include "imagewindow.h"

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}

enum SystemState{
    INIT,
    CAPTURE,
    RUNNING
};

QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    QImage currentFrame;

    bool isDoorOpen = false;
    SystemState systemState =  INIT;
    QTimer *timer_doorState;
    ObservableBool *doorState ;
    // QListView listView;
    QStringListModel* listView_directory_model;



    //cameraThread *cameraThread;

    QBluetoothDeviceDiscoveryAgent *discoveryAgent;

private slots:
    void addDevice(const QBluetoothDeviceInfo &device);
    void do_newConnection();
    void do_socketConnected();
    void do_socketDisconnected();
    void do_socketReadyRead();
    void do_timer_doorState_Timeout();
    void do_updateDoorStatusUi(void);

    void on_pushButton_tcpStart_clicked();

    void on_pushButton_tcpEnd_clicked();

    void on_pushButton_camSuspend_clicked();

    void on_pushButton_tcpSend_clicked();

    void on_pushButton_savePicture_clicked();

    void on_pushButton_openDoor_clicked();

    void on_pushButton_camSelect_clicked();

    void on_pushButton_showImage_clicked();

    void on_pushButton_captureState_clicked();

    void on_pushButton_faceRegister_clicked();

    void on_pushButton_checkDirectory_clicked();

    void on_pushButton_deleteFace_clicked();




    void on_pushButton_camStop_clicked();

private:
    QString filter = "图片文件(*.bmp *.jpg *.png);;"
                     "BMP文件(*.bmp);;JPG文件(*.jpg);;PNG文件(*.png)";

private:
    Ui::MainWindow *ui;
    QTcpServer *tcp_server;
    QTcpSocket *tcp_socket;
    QString getlocalIP();
    bool waitForAck(QString ACK ,int timeoutMs );
    QString  waitForStringAck(int timeoutMs,QString ACK);

};
#endif // MAINWINDOW_H
